$(function(){
    
    $("#form_boletimgabarito").validate({
        onfocusout: function (element) {
            $(element).valid();
        },
        errorPlacement: function(error, element) 
        {
            element.attr('title', error.text());
            $(".error").tooltip({   
                position: {
                    my: "center bottom-10",
                    at: "right top",
                    using: function(position, feedback) {
                        $(this).css(position);
                        $("<div>").addClass("arrow").addClass(feedback.vertical).addClass(feedback.horizontal).appendTo(this);
                    }
                },
                tooltipClass: "ttError"
            }); 
        }
    });
    
    $("#dialog").dialog({ 
        autoOpen: false,
        modal: true,
        width: 850,
        height: 470,
        title: "Selecione uma pergunta."
        
    });
    
    $(".clk_sel_blg" ).click(function(){
        $.post(URLBASE+'/boletimgabarito/popup',{ bol_id: $('#BOL_ID').val() }, function(data) {
            $("#dialog").html(data);
            $("#dialog").dialog("open");
        });
    });
    
    $(".ajx_blg_nom").autocomplete({
        source: URLBASE+'/boletimgabarito/find?bol_id='+$('#BOL_ID').val(),
        minLength: 1,
        select: function( event, ui ) {
            $(".ajx_blg_id").val(ui.item.id);
            $(".ajx_blg_nom").val(ui.item.value);
        }
    });
    
    $('#form-search_ajx').submit(function() {
        $.post(URLBASE+'/boletimgabarito/popup?bol_id='+$('#BOL_ID').val(),$('#form-search_ajx').serialize(),function(data) {
            $("#dialog").html(data);
        });
        return false;
    });
    
    $('.page_ajx_blg').click(function() {
        $.post(URLBASE+'/boletimgabarito/popup/pagina/'+$(this).attr('page')+'?bol_id='+$('#BOL_ID').val(),$('#form-search_ajx').serialize(),function(data) {
            $("#dialog").html(data);
        });
        return false;
    });
    
    
});
function setValor(val,nom){
    $('.ajx_blg_id').val(val);
    $('.ajx_blg_nom').val(nom);
    $("#dialog").dialog( "close" );
}
